package com.aaa.work1226.controller;


import com.aaa.work1226.entity.Userinfo;
import com.aaa.work1226.entity.vo.PageParam;
import com.aaa.work1226.entity.vo.ResponseMode;
import com.aaa.work1226.service.IUserinfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ql
 * @since 2022-12-26
 */
@RestController
@RequestMapping("/userinfo")
public class UserinfoController {

    @Autowired
    private IUserinfoService userinfoService;


    @DeleteMapping("{id}")
    public ResponseMode delById(@PathVariable Integer id){
        ResponseMode<Object> responseMode = new ResponseMode<>();
        boolean b = userinfoService.removeById(id);
        if (b){
            responseMode.setMsg("删除成功");
        }
        return responseMode;
    }

    @GetMapping("sellike")
    public ResponseMode<Page<Userinfo>> selLike(Userinfo userinfo, PageParam pageParam){
        IPage<Userinfo> userinfoPage = userinfoService.selNameAndAge(userinfo, pageParam);
        System.out.println("userinfoPage = " + userinfoPage.getRecords());

        return new ResponseMode<Page<Userinfo>>().setExtra(userinfoPage);
    }


    @PostMapping("addOrUpd")
    public ResponseMode addOrUpd(Userinfo userinfo){
        boolean b = userinfoService.saveOrUpdate(userinfo);
        ResponseMode<Object> responseMode = new ResponseMode<>();
        if (b) {
            responseMode.setCode(0).setMsg("成功");
        }

        return responseMode;
    }



}

